<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>Nginx 中文文档 - Module ngx_http_perl_module | Docs4dev</title>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="Nginx (engine x) 是一个高性能的HTTP和反向代理服务，也是一个IMAP/POP3/SMTP服务。">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="true">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta property="og:type" content="website">
<meta property="og:title" content="Nginx 中文文档 - Module ngx_http_perl_module">
<meta property="og:url" content="https://www.docs4dev.com/docs/zh/nginx/current/reference/http-ngx_http_perl_module.html">
<meta property="og:site_name" content="Docs4dev">
<meta property="og:locale" content="zh_CN">
<meta name="twitter:card" content="Nginx (engine x) 是一个高性能的HTTP和反向代理服务，也是一个IMAP/POP3/SMTP服务。">
<meta name="generator" content="Docs4dev template engine">
<link rel="stylesheet" href="static/css/app.min.css">
<link rel="shortcut icon" href="https://www.docs4dev.com/static/images/favicon.ico" type="image/x-icon">
<script async="" src="static/js/js.js"></script>
<script async="" src="static/js/adsbygoogle.js" crossorigin="anonymous"></script>
<script>
    window.dataLayer = window.dataLayer || [];

    function gtag() {
      dataLayer.push(arguments);
    }

    gtag('js', new Date());
    gtag('config', 'UA-129571937-1');
  </script>
<link rel="amphtml" href="https://www.docs4dev.com/amp/docs/zh/nginx/current/reference/http-ngx_http_perl_module.html">
<script type="application/ld+json">{"name":null,"headline":"Nginx 中文文档-Module ngx_http_perl_module","inLanguage":"zh-CN","version":"current","image":"/static/icon/icon-nginx.svg","datePublished":"2021-05-20T12:51:01Z","dateCreated":"2021-05-20T12:51:01Z","dateModified":"2021-07-07T12:48:29Z","@context":"https://schema.org/","@type":"APIReference","abstract":"Nginx (engine x) 是一个高性能的HTTP和反向代理服务，也是一个IMAP/POP3/SMTP服务。"}</script>
</head>
<body>
<div class="book with-summary">
<div class="book-summary">
<div class="logo">
<a href="index.html" style="color: inherit;">
<img src="static/picture/icon-nginx.svg" style="width: 48px; height: 48px;" alt="Logo">
</a>
<b style="color: inherit; margin-left: 8px;">Nginx 中文文档</b>
</div>
<div class="item">
<div>
<label for="version">版本</label>
<select id="version" onchange="onVersionChange(this)">
<option value="current" selected="selected">current</option>
</select>
</div>
<div style="margin-top: 8px;">
<label for="language">语言</label>
<select id="language" onchange="onLangChange(this)" value="zh">
<option value="en">English</option>
<option value="zh" selected="selected">中文</option>
</select>
</div>

</div>
<div class="item menus">
<a title="Table of Contents" style="margin-right: 8px;" href="index.html">
<i class="fa fa-chevron-left"></i>
<span style="margin-left: 2px;">返回目录</span>
</a>
</div>
<nav role="navigation" id="navigation">
<ul class="summary">
<li class="chapter"> <a href="install.html" title="Introduction"> Introduction </a>
<ul class="articles">
<li class="chapter"> <a href="install.html" title="Installing nginx"> Installing nginx </a> </li>
<li class="chapter"> <a href="configure.html" title="从源代码构建  Nginx"> 从源代码构建 Nginx </a> </li>
<li class="chapter"> <a href="beginners_guide.html" title="Beginner's Guide"> Beginner's Guide </a> </li>
<li class="chapter"> <a href="control.html" title="Controlling nginx"> Controlling nginx </a> </li>
<li class="chapter"> <a href="events.html" title="连接处理方法"> 连接处理方法 </a> </li>
<li class="chapter"> <a href="hash.html" title="设置哈希"> 设置哈希 </a> </li>
<li class="chapter"> <a href="debugging_log.html" title="调试日志"> 调试日志 </a> </li>
<li class="chapter"> <a href="syslog.html" title="记录到系统日志"> 记录到系统日志 </a> </li>
<li class="chapter"> <a href="syntax.html" title="配置文件测量单位"> 配置文件测量单位 </a> </li>
<li class="chapter"> <a href="switches.html" title="Command-line parameters"> Command-line parameters </a> </li>
<li class="chapter"> <a href="windows.html" title="Windows 版  Nginx"> Windows 版 Nginx </a> </li>
<li class="chapter"> <a href="http-request_processing.html" title="Nginx 如何处理请求"> Nginx 如何处理请求 </a> </li>
<li class="chapter"> <a href="http-server_names.html" title="Server names"> Server names </a> </li>
<li class="chapter"> <a href="http-load_balancing.html" title="使用  Nginx 作为  HTTP 负载均衡器"> 使用 Nginx 作为 HTTP 负载均衡器 </a> </li>
<li class="chapter"> <a href="http-configuring_https_servers.html" title="配置  HTTPS 服务器"> 配置 HTTPS 服务器 </a> </li>
<li class="chapter"> <a href="stream-stream_processing.html" title="Nginx 如何处理  TCP/UDP 会话"> Nginx 如何处理 TCP/UDP 会话 </a> </li>
<li class="chapter"> <a href="njs-index.html" title="用  njs 编写脚本"> 用 njs 编写脚本 </a> </li>
</ul> </li>
<li class="chapter"> <a href="howto_build_on_win32.html" title="How-To"> How-To </a>
<ul class="articles">
<li class="chapter"> <a href="howto_build_on_win32.html" title="使用  Visual C 在  Win32 平台上构建  Nginx"> 使用 Visual C 在 Win32 平台上构建 Nginx </a> </li>
<li class="chapter"> <a href="nginx_dtrace_pid_provider.html" title="使用  DTrace pid 提供程序调试  nginx"> 使用 DTrace pid 提供程序调试 nginx </a> </li>
<li class="chapter"> <a href="http-converting_rewrite_rules.html" title="转换重写规则"> 转换重写规则 </a> </li>
<li class="chapter"> <a href="http-websocket.html" title="WebSocket proxying"> WebSocket proxying </a> </li>
</ul> </li>
<li class="chapter"> <a href="contributing_changes.html" title="Development"> Development </a>
<ul class="articles">
<li class="chapter"> <a href="contributing_changes.html" title="Contributing Changes"> Contributing Changes </a> </li>
<li class="chapter"> <a href="dev-development_guide.html" title="Development guide"> Development guide </a> </li>
</ul> </li>
<li class="chapter"> <a href="dirindex.html" title="Modules reference"> Modules reference </a>
<ul class="articles">
<li class="chapter"> <a href="dirindex.html" title="指令的字母索引"> 指令的字母索引 </a> </li>
<li class="chapter"> <a href="varindex.html" title="变量按字母顺序索引"> 变量按字母顺序索引 </a> </li>
<li class="chapter"> <a href="ngx_core_module.html" title="Core functionality"> Core functionality </a> </li>
<li class="chapter"> <a href="http-ngx_http_core_module.html" title="ngx_http_core_module"> ngx_http_core_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_access_module.html" title="ngx_http_access_module"> ngx_http_access_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_addition_module.html" title="ngx_http_addition_module"> ngx_http_addition_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_api_module.html" title="ngx_http_api_module"> ngx_http_api_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_auth_basic_module.html" title="ngx_http_auth_basic_module"> ngx_http_auth_basic_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_auth_jwt_module.html" title="ngx_http_auth_jwt_module"> ngx_http_auth_jwt_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_auth_request_module.html" title="ngx_http_auth_request_module"> ngx_http_auth_request_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_autoindex_module.html" title="ngx_http_autoindex_module"> ngx_http_autoindex_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_browser_module.html" title="ngx_http_browser_module"> ngx_http_browser_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_charset_module.html" title="ngx_http_charset_module"> ngx_http_charset_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_dav_module.html" title="ngx_http_dav_module"> ngx_http_dav_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_empty_gif_module.html" title="ngx_http_empty_gif_module"> ngx_http_empty_gif_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_f4f_module.html" title="ngx_http_f4f_module"> ngx_http_f4f_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_fastcgi_module.html" title="ngx_http_fastcgi_module"> ngx_http_fastcgi_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_flv_module.html" title="ngx_http_flv_module"> ngx_http_flv_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_geo_module.html" title="ngx_http_geo_module"> ngx_http_geo_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_geoip_module.html" title="ngx_http_geoip_module"> ngx_http_geoip_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_grpc_module.html" title="ngx_http_grpc_module"> ngx_http_grpc_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_gunzip_module.html" title="ngx_http_gunzip_module"> ngx_http_gunzip_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_gzip_module.html" title="ngx_http_gzip_module"> ngx_http_gzip_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_gzip_static_module.html" title="ngx_http_gzip_static_module"> ngx_http_gzip_static_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_headers_module.html" title="ngx_http_headers_module"> ngx_http_headers_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_hls_module.html" title="ngx_http_hls_module"> ngx_http_hls_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_image_filter_module.html" title="ngx_http_image_filter_module"> ngx_http_image_filter_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_index_module.html" title="ngx_http_index_module"> ngx_http_index_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_js_module.html" title="ngx_http_js_module"> ngx_http_js_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_keyval_module.html" title="ngx_http_keyval_module"> ngx_http_keyval_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_limit_conn_module.html" title="ngx_http_limit_conn_module"> ngx_http_limit_conn_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_limit_req_module.html" title="ngx_http_limit_req_module"> ngx_http_limit_req_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_log_module.html" title="ngx_http_log_module"> ngx_http_log_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_map_module.html" title="ngx_http_map_module"> ngx_http_map_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_memcached_module.html" title="ngx_http_memcached_module"> ngx_http_memcached_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_mirror_module.html" title="ngx_http_mirror_module"> ngx_http_mirror_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_mp4_module.html" title="ngx_http_mp4_module"> ngx_http_mp4_module </a> </li>
<li class="chapter"> <a href="" title="ngx_http_perl_module"> ngx_http_perl_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_proxy_module.html" title="ngx_http_proxy_module"> ngx_http_proxy_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_random_index_module.html" title="ngx_http_random_index_module"> ngx_http_random_index_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_realip_module.html" title="ngx_http_realip_module"> ngx_http_realip_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_referer_module.html" title="ngx_http_referer_module"> ngx_http_referer_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_rewrite_module.html" title="ngx_http_rewrite_module"> ngx_http_rewrite_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_scgi_module.html" title="ngx_http_scgi_module"> ngx_http_scgi_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_secure_link_module.html" title="ngx_http_secure_link_module"> ngx_http_secure_link_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_session_log_module.html" title="ngx_http_session_log_module"> ngx_http_session_log_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_slice_module.html" title="ngx_http_slice_module"> ngx_http_slice_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_spdy_module.html" title="ngx_http_spdy_module"> ngx_http_spdy_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_split_clients_module.html" title="ngx_http_split_clients_module"> ngx_http_split_clients_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_ssi_module.html" title="ngx_http_ssi_module"> ngx_http_ssi_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_ssl_module.html" title="ngx_http_ssl_module"> ngx_http_ssl_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_status_module.html" title="ngx_http_status_module"> ngx_http_status_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_stub_status_module.html" title="ngx_http_stub_status_module"> ngx_http_stub_status_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_sub_module.html" title="ngx_http_sub_module"> ngx_http_sub_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_upstream_module.html" title="ngx_http_upstream_module"> ngx_http_upstream_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_upstream_conf_module.html" title="ngx_http_upstream_conf_module"> ngx_http_upstream_conf_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_upstream_hc_module.html" title="ngx_http_upstream_hc_module"> ngx_http_upstream_hc_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_userid_module.html" title="ngx_http_userid_module"> ngx_http_userid_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_uwsgi_module.html" title="ngx_http_uwsgi_module"> ngx_http_uwsgi_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_v2_module.html" title="ngx_http_v2_module"> ngx_http_v2_module </a> </li>
<li class="chapter"> <a href="http-ngx_http_xslt_module.html" title="ngx_http_xslt_module"> ngx_http_xslt_module </a> </li>
<li class="chapter"> <a href="mail-ngx_mail_core_module.html" title="ngx_mail_core_module"> ngx_mail_core_module </a> </li>
<li class="chapter"> <a href="mail-ngx_mail_auth_http_module.html" title="ngx_mail_auth_http_module"> ngx_mail_auth_http_module </a> </li>
<li class="chapter"> <a href="mail-ngx_mail_proxy_module.html" title="ngx_mail_proxy_module"> ngx_mail_proxy_module </a> </li>
<li class="chapter"> <a href="mail-ngx_mail_ssl_module.html" title="ngx_mail_ssl_module"> ngx_mail_ssl_module </a> </li>
<li class="chapter"> <a href="mail-ngx_mail_imap_module.html" title="ngx_mail_imap_module"> ngx_mail_imap_module </a> </li>
<li class="chapter"> <a href="mail-ngx_mail_pop3_module.html" title="ngx_mail_pop3_module"> ngx_mail_pop3_module </a> </li>
<li class="chapter"> <a href="mail-ngx_mail_smtp_module.html" title="ngx_mail_smtp_module"> ngx_mail_smtp_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_core_module.html" title="ngx_stream_core_module"> ngx_stream_core_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_access_module.html" title="ngx_stream_access_module"> ngx_stream_access_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_geo_module.html" title="ngx_stream_geo_module"> ngx_stream_geo_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_geoip_module.html" title="ngx_stream_geoip_module"> ngx_stream_geoip_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_js_module.html" title="ngx_stream_js_module"> ngx_stream_js_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_keyval_module.html" title="ngx_stream_keyval_module"> ngx_stream_keyval_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_limit_conn_module.html" title="ngx_stream_limit_conn_module"> ngx_stream_limit_conn_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_log_module.html" title="ngx_stream_log_module"> ngx_stream_log_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_map_module.html" title="ngx_stream_map_module"> ngx_stream_map_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_proxy_module.html" title="ngx_stream_proxy_module"> ngx_stream_proxy_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_realip_module.html" title="ngx_stream_realip_module"> ngx_stream_realip_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_return_module.html" title="ngx_stream_return_module"> ngx_stream_return_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_split_clients_module.html" title="ngx_stream_split_clients_module"> ngx_stream_split_clients_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_ssl_module.html" title="ngx_stream_ssl_module"> ngx_stream_ssl_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_ssl_preread_module.html" title="ngx_stream_ssl_preread_module"> ngx_stream_ssl_preread_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_upstream_module.html" title="ngx_stream_upstream_module"> ngx_stream_upstream_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_upstream_hc_module.html" title="ngx_stream_upstream_hc_module"> ngx_stream_upstream_hc_module </a> </li>
<li class="chapter"> <a href="stream-ngx_stream_zone_sync_module.html" title="ngx_stream_zone_sync_module"> ngx_stream_zone_sync_module </a> </li>
<li class="chapter"> <a href="ngx_google_perftools_module.html" title="ngx_google_perftools_module"> ngx_google_perftools_module </a> </li>
</ul> </li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<header class="book-header">
<div class="dropdown pull-right js-toolbar-action">
<a class="btn toggle-dropdown" aria-label="Language" href="#">
<i class="fa fa-globe"></i>
</a>
<div class="dropdown-menu dropdown-left">
<div class="dropdown-caret"><span class="caret-outer"></span><span class="caret-inner"></span></div>
<div class="buttons">
<button class="button size-1" onclick="changeLang('zh_CN')">中文</button>
</div>
<div class="buttons">
<button class="button size-1" onclick="changeLang('en_US')">English</button>
</div>
</div>
</div>
<a class="btn pull-right js-toolbar-action non-mobile" aria-label="Sign up" href="register.html">
<i class="fa fa-sign-in"></i> <span>注册</span>
</a>
 <a class="btn pull-right js-toolbar-action non-mobile" aria-label="Sign in" href="register.html">
<i class="fa fa-sign-in"></i>
<span>登录</span>
</a>
<a class="btn pull-left js-toolbar-action btn-summary" href="#"><i class="fa fa-align-justify"></i></a>
<div class="dropdown pull-left font-settings js-toolbar-action">
<a class="btn toggle-dropdown" aria-label="Font Settings" href="#">
<i class="fa fa-font"></i>
</a>
<div class="dropdown-menu dropdown-right">
<div class="dropdown-caret"><span class="caret-outer"></span><span class="caret-inner"></span></div>
<div class="buttons">
<button class="button size-2 font-reduce">A</button>
<button class="button size-2 font-enlarge">A</button>
</div>
<div class="buttons">
<button class="button size-2 family-serif">Serif</button>
<button class="button size-2 family-sans">Sans</button>
</div>
<div class="buttons">
<button class="button size-3 theme-white">White</button>
<button class="button size-3 theme-sepia">Sepia</button>
<button class="button size-3 theme-night">Night</button>
</div>
</div>
</div>
<a class="btn pull-left js-toolbar-action non-mobile" aria-label="Home" href="zh.html">
<i class="fa fa-home"></i> <span>首页</span>
</a>
<a class="btn pull-left js-toolbar-action non-mobile" aria-label="Guide" href="javascript:window.open('https://www.javadoc.org/');">
<i class="fa fa-book"></i> <span>API Docs</span>
</a>
<a class="btn pull-left js-toolbar-action non-mobile" aria-label="Tools" href="index1.html">
<i class="fa fa-gears"></i> <span>工具</span>
</a>
<div class="dropdown pull-left js-toolbar-action mobile">
<a class="btn toggle-dropdown" aria-label="Language" href="#">
<i class="fa fa-chevron-down"></i>
</a>
<div class="dropdown-menu dropdown-right">
<div class="dropdown-caret"><span class="caret-outer"></span><span class="caret-inner"></span></div>
<div class="buttons">
<a class="button size-1" aria-label="Home" href="zh.html">
<i class="fa fa-home"></i> <span>首页</span>
</a>
</div>
<div class="buttons">
<a class="button size-1" aria-label="Guide" href="javascript:window.open('https://www.javadoc.org/');">
<i class="fa fa-book"></i> <span>API Docs</span>
</a>
</div>
<div class="buttons">
<a class="button size-1" aria-label="Tools" href="index1.html">
<i class="fa fa-gears"></i> <span>工具</span>
</a>
</div>
</div>
</div>
<div id="autocomplete" class="pull-right"></div>
<span id="toolbar-title"></span>
</header>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal markdown-section">
<div id="content">
<h1>Module ngx_http_perl_module</h1>
<div><ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6108808167664152" data-ad-slot="6964403648"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
<div><ul>
<li><a href="#issues">Known Issues</a></li>
<li><a href="#example">Example Configuration</a></li>
<li><a href="#directives">Directives</a>
<ul>
<li><a href="#perl">perl</a></li>
<li><a href="#perl_modules">perl_modules</a></li>
<li><a href="#perl_require">perl_require</a></li>
<li><a href="#perl_set">perl_set</a></li>
</ul>
</li>
<li><a href="#ssi">从 SSI 调用 Perl</a></li>
<li><a href="#methods">$ r 请求对象方法</a><br><a href="" id="summary"></a></li>
</ul>
<p><code>ngx_http_perl_module</code>模块用于在 Perl 中实现位置和变量处理程序，并将 Perl 调用插入 SSI。</p>
<p>默认情况下未构建此模块，应使用<code>--with-http_perl_module</code>配置参数启用它。</p>
<div class="alert callout info"><p class="title"><i class="fa fa-info-circle"></i>Note</p><div><p>此模块要求<a href="javascript:window.open('https://www.perl.org/get.html');" target="_blank" rel="noopener noreferrer">Perl</a> 5.6.1 或更高版本。 C 编译器应与用于构建 Perl 的编译器兼容。</p>
</div></div>
<p><a href="" id="issues"></a></p>
<h4 id="known-issues"><a href="#known-issues" id="known-issues"></a>Known Issues</h4>
<p>该模块是实验性的，警告购买者适用。</p>
<p>为了使 Perl 在重新配置期间重新编译已修改的模块，应使用<code>-Dusemultiplicity=yes</code>或<code>-Dusethreads=yes</code>参数来构建它。另外，要使 Perl 在运行时泄漏较少的内存，应使用<code>-Dusemymalloc=no</code>参数构建它。要在已经构建的 Perl 中检查这些参数的值(在示例中指定了首选值)，请运行：</p>
<pre><code class="hljs language-shell">$ perl -V:usemultiplicity -V:usemymalloc
usemultiplicity='define';
usemymalloc='n';
</code></pre>
<p>请注意，在使用新的<code>-Dusemultiplicity=yes</code>或<code>-Dusethreads=yes</code>参数重建 Perl 之后，所有二进制 Perl 模块也必须重建-它们将仅停止使用新的 Perl。</p>
<p>每次重新配置后，主进程和然后的工作进程的大小都有可能增加。如果主进程增长到不可接受的大小，则可以应用<a href="control.html#upgrade">live upgrade</a>过程，而无需更改可执行文件。</p>
<p>当 Perl 模块执行长时间运行的操作(例如解析域名，连接到另一台服务器或查询数据库)时，将不会处理分配给当前工作进程的其他请求。因此，建议仅执行具有可预测且执行时间短的操作，例如访问本地文件系统。</p>
<p><a href="" id="example"></a></p>
<h4 id="example-configuration"><a href="#example-configuration" id="example-configuration"></a>Example Configuration</h4>
<pre><code class="hljs language-shell">http {

    perl_modules perl/lib;
    perl_require hello.pm;

    perl_set $msie6 '

        sub {
            my $r = shift;
            my $ua = $r-&gt;header_in(&quot;User-Agent&quot;);

            return &quot;&quot; if $ua =~ /Opera/;
            return &quot;1&quot; if $ua =~ / MSIE [6-9]\.\d+/;
            return &quot;&quot;;
        }

    ';

    server {
        location / {
            perl hello::handler;
        }
    }
</code></pre>
<p><code>perl/lib/hello.pm</code>模块：</p>
<pre><code class="hljs language-shell">package hello;

use nginx;

sub handler {
    my $r = shift;

    $r-&gt;send_http_header(&quot;text/html&quot;);
    return OK if $r-&gt;header_only;

    $r-&gt;print(&quot;hello!\n<br>&quot;);

    if (-f $r-&gt;filename or -d _) {
        $r-&gt;print($r-&gt;uri, &quot; exists!\n&quot;);
    }

    return OK;
}

1;
__END__
</code></pre>
<p><a href="" id="directives"></a></p>
<h4 id="directives"><a href="#directives" id="directives"></a>Directives</h4>
<p><a href="" id="perl"></a></p>
<table>
<thead></thead>
<tbody>
<tr><td>Syntax:</td><td><code>perl module::function|'sub { ... }';</code></td></tr>
<tr><td>Default:</td><td>—</td></tr>
<tr><td>Context:</td><td><code>location</code> , <code>limit_except</code></td></tr>
</tbody>
</table>
<p>为给定位置设置一个 Perl 处理程序。</p>
<p><a href="" id="perl_modules"></a></p>
<table>
<thead></thead>
<tbody>
<tr><td>Syntax:</td><td><code>perl_modules path;</code></td></tr>
<tr><td>Default:</td><td>—</td></tr>
<tr><td>Context:</td><td><code>http</code></td></tr>
</tbody>
</table>
<p>为 Perl 模块设置附加路径。</p>
<p><a href="" id="perl_require"></a></p>
<table>
<thead></thead>
<tbody>
<tr><td>Syntax:</td><td><code>perl_require module;</code></td></tr>
<tr><td>Default:</td><td>—</td></tr>
<tr><td>Context:</td><td><code>http</code></td></tr>
</tbody>
</table>
<p>定义将在每次重新配置期间加载的模块的名称。可以存在多个<code>perl_require</code>指令。</p>
<p><a href="" id="perl_set"></a></p>
<table>
<thead></thead>
<tbody>
<tr><td>Syntax:</td><td><code>perl_set $variable module::function|'sub { ... }';</code></td></tr>
<tr><td>Default:</td><td>—</td></tr>
<tr><td>Context:</td><td><code>http</code></td></tr>
</tbody>
</table>
<p>为指定的变量安装一个 Perl 处理程序。</p>
<p><a href="" id="ssi"></a></p>
<h4 id="从--ssi-调用--perl"><a href="#从--ssi-调用--perl" id="从--ssi-调用--perl"></a>从 SSI 调用 Perl</h4>
<p>调用 Perl 的 SSI 命令具有以下格式：</p>
<pre><code class="hljs language-shell">&lt;!--# perl sub=&quot;module::function&quot; arg=&quot;parameter1&quot; arg=&quot;parameter2&quot; ...
--&gt;
</code></pre>
<p><a href="" id="methods"></a></p>
<h4 id="r-请求对象方法"><a href="#r-请求对象方法" id="r-请求对象方法"></a>$ r 请求对象方法</h4>
<ul>
<li>
<p><code>$r-&gt;args</code></p>
<ul>
<li>返回请求参数。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;filename</code></p>
<ul>
<li>返回与请求 URI 相对应的文件名。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;has_request_body(handler)</code></p>
<ul>
<li>如果请求中没有主体，则返回 0.如果有正文，则为请求设置指定的处理程序，并返回 1.读取请求主体后，nginx 将调用指定的处理程序。请注意，处理函数应通过引用传递。例：</li>
</ul>
</li>
</ul>
<pre><code class="hljs language-shell">package hello;

use nginx;

sub handler {
    my $r = shift;

    if ($r-&gt;request_method ne &quot;POST&quot;) {
        return DECLINED;
    }

    if ($r-&gt;has_request_body(\&amp;post)) {
        return OK;
    }

    return HTTP_BAD_REQUEST;
}

sub post {
    my $r = shift;

    $r-&gt;send_http_header;

    $r-&gt;print(&quot;request_body: \&quot;&quot;, $r-&gt;request_body, &quot;\&quot;<br>&quot;);
    $r-&gt;print(&quot;request_body_file: \&quot;&quot;, $r-&gt;request_body_file, &quot;\&quot;<br>\n&quot;);

    return OK;
}

1;

__END__
</code></pre>
<ul>
<li>
<p><code>$r-&gt;allow_ranges</code></p>
<ul>
<li>发送响应时启用字节范围的使用。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;discard_request_body</code></p>
<ul>
<li>指示 nginx 放弃请求主体。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;header_in(field)</code></p>
<ul>
<li>返回指定的客户端请求 Headers 字段的值。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;header_only</code></p>
<ul>
<li>确定是将整个响应还是仅将其 Headers 发送给客户端。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;header_out(field, value)</code></p>
<ul>
<li>为指定的响应头字段设置一个值。</li>
</ul>
</li>
</ul>
<h4 id="r-internal-redirecturi"><a href="#r_internal_redirect" id="r_internal_redirect"></a> $r-&gt;internal_redirect(uri)</h4>
<ul>
<li>内部重定向到指定的<code>uri</code>。 Perl 处理程序执行完成后，发生实际的重定向。</li>
</ul>
<div class="alert callout info"><p class="title"><i class="fa fa-info-circle"></i>Note</p><div><p>从 1.17.2 版开始，该方法接受转义的 URI，并支持重定向到命名位置。</p>
</div></div>
<ul>
<li>
<p><code>$r-&gt;log_error(errno, message)</code></p>
<ul>
<li>将指定的<code>message</code>写入<a href="ngx_core_module.html#error_log">error_log</a>。如果<code>errno</code>不为零，则错误代码及其描述将附加到消息中。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;print(text, ...)</code></p>
<ul>
<li>将数据传递给客户端。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;request_body</code></p>
<ul>
<li>如果尚未将客户请求主体写入临时文件，则返回该请求主体。为确保客户端请求主体在内存中，其大小应受<a href="http-ngx_http_core_module.html#client_max_body_size">client_max_body_size</a>限制，并应使用<a href="http-ngx_http_core_module.html#client_body_buffer_size">client_body_buffer_size</a>设置足够的缓冲区大小。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;request_body_file</code></p>
<ul>
<li>返回带有客户端请求正文的文件名。处理后，应删除文件。要始终将请求正文写入文件，应启用<a href="http-ngx_http_core_module.html#client_body_in_file_only">client_body_in_file_only</a>。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;request_method</code></p>
<ul>
<li>返回客户端请求的 HTTP 方法。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;remote_addr</code></p>
<ul>
<li>返回客户端 IP 地址。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;flush</code></p>
<ul>
<li>立即将数据发送到客户端。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;sendfile(name[, offset[, length]])</code></p>
<ul>
<li>将指定的文件内容发送到客户端。可选参数指定要传输的数据的初始偏移量和长度。实际的数据传输发生在 Perl 处理程序完成之后。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;send_http_header([type])</code></p>
<ul>
<li>将响应 Headers 发送到客户端。可选的<code>type</code>参数设置“ Content-Type”响应头字段的值。如果值为空字符串，则不会发送“ Content-Type”头字段。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;status(code)</code></p>
<ul>
<li>设置响应码。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;sleep(milliseconds, handler)</code></p>
<ul>
<li>设置指定的处理程序，并在指定时间内停止请求处理。同时，nginxcontinue 处理其他请求。在指定的时间过去之后，nginx 将调用已安装的处理程序。请注意，处理函数应通过引用传递。为了在处理程序之间传递数据，应使用<code>$r-&gt;variable()</code>。例：</li>
</ul>
</li>
</ul>
<pre><code class="hljs language-shell">package hello;

use nginx;

sub handler {
    my $r = shift;

    $r-&gt;discard_request_body;
    $r-&gt;variable(&quot;var&quot;, &quot;OK&quot;);
    $r-&gt;sleep(1000, \&amp;next);

    return OK;
}

sub next {
    my $r = shift;

    $r-&gt;send_http_header;
    $r-&gt;print($r-&gt;variable(&quot;var&quot;));

    return OK;
}

1;

__END__
</code></pre>
<ul>
<li>
<p><code>$r-&gt;unescape(text)</code></p>
<ul>
<li>解码以“％XX”形式编码的文本。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;uri</code></p>
<ul>
<li>返回请求 URI。</li>
</ul>
</li>
<li>
<p><code>$r-&gt;variable(name[, value])</code></p>
<ul>
<li>返回或设置指定变量的值。变量是每个请求的局部变量。</li>
</ul>
</li>
</ul>
</div>
</div>
</section>
<div class="right-sidebar">
<div class="affix"><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6108808167664152" data-ad-slot="3102929424" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
</div>
</div>
<div class="ft">
<a href="#toolbar-title" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a>
<footer class="footer">
<div class="footer__container--normal">
<img alt="扫码关注公众号" title="扫码关注公众号" src="static/picture/qr-code.png" width="170" height="170">
<div class="footer__description--normal">
<p class="paragraph footer__author--normal">Docs4dev<sup class="super">&#xAE;</sup>
</p>
<p class="paragraph footer__quote&#45;&#45;normal">
如果你在使用过程中遇到任何问题，可以在 <a href="javascript:window.open('https://github.com/docs4dev/docs4dev-issues');" target="_blank" rel="noopener noreferrer">这里<i class="fa fa-external-link"></i></a> 提issue。
</p>
<div class="footer__main--normal">
<p class="paragraph footer__main__paragraph--normal copyright" style="color: #666 !important;">
<a href="javascript:window.open('https://beian.miit.gov.cn/');">
蜀ICP备14021783号-6
</a>
</p>
<p class="paragraph footer__main__paragraph--normal copyright" style="color: #666 !important;">
Copyright &#xA9; Docs4dev all
right reserved, powered by <a href="index2.html" target="_blank">Docs4dev</a></p>
</div>
</div>
</div>
<div class="box__issues">
</div>
</footer>
</div>
</div>
</div>
</div>
</div>
<script>
  var hasToc = true;
  /*  var downloadable = /!*false*!/ false;
    var editable = /!*false*!/ false;
    var code = /!*"nginx"*!/ false;
    var version = /!*"current"*!/ false;
    var type = /!*"reference"*!/ false;
    var lang = /!*"zh"*!/ 'en';
    //edit link
    require(["gitbook", "jQuery"], function (gitbook, $) {
      gitbook.events.bind('start', function (e, config) {
        // Add edit toolbar to left
        var chapterId = /!*17778*!/ 0;
        if (downloadable) {
          gitbook.toolbar.createButton({
            icon: 'fa fa-download',
            text: '下载',
            onClick: function () {
              window.open('/download?code=' + code + '&version=' + version + '&type=' + type + '&lang=' + lang);
            }
          });
        }
        if (editable) {
          gitbook.toolbar.createButton({
            icon: 'fa fa-edit',
            text: '编辑此页',
            onClick: function () {
              window.open('/docs/edit?chapterId=' + chapterId + '&lang=' + lang);
            }
          });
        }
      });
    });*/
</script>
<script>
    var code = "nginx";
    var lang = "zh";
  </script>

<script src="static/js/autocomplete-js.js"></script>
<script src="static/js/app.min.js"></script>
<script src="static/js/search.min.js"></script>
</body>
</html>
